package com.esri.android.map.popup;

import android.content.Context;
import android.database.DataSetObserver;
import android.view.View;
import android.widget.LinearLayout;
import com.esri.core.map.popup.PopupInfo;
import java.util.Map;

/* loaded from: classes.dex */
public class ArcGISAttributeView extends LinearLayout implements AttributeView, PopupEditable, PopupRefreshable, PopupValid {
    Popup a;
    private ArcGISAttributesAdapter b;
    private ArcGISAttributesAdapter c;
    private DataSetObserver d;
    private boolean e;

    public ArcGISAttributeView(Context context, Popup popup) {
        super(context);
        this.d = new DataSetObserver() { // from class: com.esri.android.map.popup.ArcGISAttributeView.1
            @Override // android.database.DataSetObserver
            public void onChanged() {
                ArcGISAttributeView.this.refresh();
            }
        };
        this.e = false;
        setOrientation(1);
        LinearLayout.LayoutParams generateDefaultLayoutParams = generateDefaultLayoutParams();
        generateDefaultLayoutParams.setMargins(0, 10, 0, 10);
        setLayoutParams(generateDefaultLayoutParams);
        this.a = popup;
        PopupInfo popupInfo = popup.a;
        if (popupInfo != null && popupInfo.getDescription() != null && !popupInfo.getDescription().equalsIgnoreCase("null")) {
            try {
                setReadOnlyAdapter(new ArcGISDescriptionAdapter(context, popup));
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            setReadOnlyAdapter(new ArcGISReadOnlyAttributesAdapter(context, popup));
        }
        setEditAdapter(new ArcGISEditAttributesAdapter(context, popup));
    }

    public ArcGISAttributesAdapter getReadOnlyAdapter() {
        return this.b;
    }

    public void setReadOnlyAdapter(ArcGISAttributesAdapter arcGISAttributesAdapter) {
        ArcGISAttributesAdapter arcGISAttributesAdapter2 = this.b;
        if (arcGISAttributesAdapter2 != null) {
            arcGISAttributesAdapter2.unregisterDataSetObserver(this.d);
        }
        this.b = arcGISAttributesAdapter;
        arcGISAttributesAdapter.registerDataSetObserver(this.d);
        if (this.e) {
            return;
        }
        refresh();
    }

    public ArcGISAttributesAdapter getEditAdapter() {
        return this.c;
    }

    public void setEditAdapter(ArcGISAttributesAdapter arcGISAttributesAdapter) {
        ArcGISAttributesAdapter arcGISAttributesAdapter2 = this.c;
        if (arcGISAttributesAdapter2 != null) {
            arcGISAttributesAdapter2.unregisterDataSetObserver(this.d);
        }
        this.c = arcGISAttributesAdapter;
        arcGISAttributesAdapter.registerDataSetObserver(this.d);
        if (this.e) {
            refresh();
        }
    }

    @Override // com.esri.android.map.popup.PopupRefreshable
    public void refresh() {
        removeAllViews();
        ArcGISAttributesAdapter arcGISAttributesAdapter = this.e ? this.c : this.b;
        arcGISAttributesAdapter.refresh();
        for (int i = 0; i < arcGISAttributesAdapter.getCount(); i++) {
            View view = arcGISAttributesAdapter.getView(i, null, this);
            if (view != null) {
                addView(view);
            }
        }
    }

    @Override // com.esri.android.map.popup.PopupEditable
    public void setEditMode(boolean z) {
        if (this.e != z) {
            this.e = z;
            refresh();
        }
    }

    @Override // com.esri.android.map.popup.AttributeView
    public Map<String, Object> getUpdatedAttributes() {
        ArcGISAttributesAdapter arcGISAttributesAdapter = this.c;
        if (arcGISAttributesAdapter != null) {
            return arcGISAttributesAdapter.b();
        }
        return null;
    }

    @Override // com.esri.android.map.popup.AttributeView
    public boolean isAttributesUpdated() {
        ArcGISAttributesAdapter arcGISAttributesAdapter = this.c;
        if (arcGISAttributesAdapter != null) {
            return arcGISAttributesAdapter.c();
        }
        return false;
    }

    @Override // com.esri.android.map.popup.PopupValid
    public boolean isValid() {
        ArcGISAttributesAdapter arcGISAttributesAdapter;
        if (!this.e || (arcGISAttributesAdapter = this.c) == null) {
            return true;
        }
        return ((PopupValid) arcGISAttributesAdapter).isValid();
    }
}
